/*  1:   */ package tt.dz.common;
/*  2:   */ 
/*  3:   */ import com.alibaba.fastjson.JSON;
/*  4:   */ import com.alibaba.fastjson.parser.Feature;
/*  5:   */ import com.alibaba.fastjson.parser.ParserConfig;
/*  6:   */ import java.beans.IntrospectionException;
/*  7:   */ import java.beans.PropertyDescriptor;
/*  8:   */ import java.lang.reflect.Field;
/*  9:   */ import java.lang.reflect.InvocationTargetException;
/* 10:   */ import java.lang.reflect.Method;
/* 11:   */ import java.text.SimpleDateFormat;
/* 12:   */ import java.util.Date;
/* 13:   */ import java.util.HashMap;
/* 14:   */ 
/* 15:   */ public final class JSONUtil
/* 16:   */ {
/* 17:20 */   private static HashMap<String, SimpleDateFormat> formats = new HashMap();
/* 18:   */   private static final long ONE_HOUR = 3600000L;
/* 19:   */   private static final long ONE_DAY = 86399000L;
/* 20:   */   
/* 21:   */   static
/* 22:   */   {
/* 23:21 */     formats.put("yyyy-MM-dd", new SimpleDateFormat("yyyy-MM-dd"));
/* 24:22 */     formats.put("yyyy-MM-dd HH:mm:ss", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
/* 25:   */     
/* 26:24 */     ParserConfig.getGlobalInstance().putDeserializer(Date.class, MyDateDeserializer.instance);
/* 27:   */   }
/* 28:   */   
/* 29:   */   public static <T> T parseObjectAsDateFormat(String text, Class<T> clazz)
/* 30:   */   {
/* 31:28 */     MyDateDeserializer.instance.setDateFormat((SimpleDateFormat)formats.get("yyyy-MM-dd"));
/* 32:29 */     T t = JSON.parseObject(text, clazz, new Feature[0]);
/* 33:30 */     parseEndDate(t);
/* 34:31 */     return t;
/* 35:   */   }
/* 36:   */   
/* 37:   */   public static <T> T parseObjectAsTimeFormat(String text, Class<T> clazz)
/* 38:   */   {
/* 39:35 */     MyDateDeserializer.instance.setDateFormat((SimpleDateFormat)formats.get("yyyy-MM-dd HH:mm:ss"));
/* 40:36 */     return JSON.parseObject(text, clazz, new Feature[0]);
/* 41:   */   }
/* 42:   */   
/* 43:   */   public static <T> T parseObject(String text, Class<T> clazz)
/* 44:   */   {
/* 45:40 */     return JSON.parseObject(text, clazz, new Feature[0]);
/* 46:   */   }
/* 47:   */   
/* 48:   */   private static <T> void parseEndDate(T t)
/* 49:   */   {
/* 50:   */     try
/* 51:   */     {
/* 52:45 */       Field[] fs = t.getClass().getDeclaredFields();
/* 53:46 */       PropertyDescriptor pd = null;
/* 54:47 */       for (Field f : fs)
/* 55:   */       {
/* 56:48 */         String fieldName = f.getName();
/* 57:49 */         if (fieldName.equals("endDate"))
/* 58:   */         {
/* 59:50 */           pd = new PropertyDescriptor(fieldName, t.getClass());
/* 60:51 */           Object o = pd.getReadMethod().invoke(t, new Object[0]);
/* 61:52 */           if (o == null) {
/* 62:   */             break;
/* 63:   */           }
/* 64:53 */           long time = ((Date)o).getTime() + 86399000L;
/* 65:54 */           Date temp = new Date(time);
/* 66:55 */           pd.getWriteMethod().invoke(t, new Object[] { temp });
/* 67:56 */           break;
/* 68:   */         }
/* 69:   */       }
/* 70:   */     }
/* 71:   */     catch (SecurityException e)
/* 72:   */     {
/* 73:61 */       e.printStackTrace();
/* 74:   */     }
/* 75:   */     catch (IllegalAccessException e)
/* 76:   */     {
/* 77:63 */       e.printStackTrace();
/* 78:   */     }
/* 79:   */     catch (IllegalArgumentException e)
/* 80:   */     {
/* 81:65 */       e.printStackTrace();
/* 82:   */     }
/* 83:   */     catch (InvocationTargetException e)
/* 84:   */     {
/* 85:67 */       e.printStackTrace();
/* 86:   */     }
/* 87:   */     catch (IntrospectionException e)
/* 88:   */     {
/* 89:69 */       e.printStackTrace();
/* 90:   */     }
/* 91:   */   }
/* 92:   */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.common.JSONUtil
 * JD-Core Version:    0.7.0.1
 */